package test;

import java.util.Arrays;
import java.util.Scanner;

class PersonSortable implements Comparable<PersonSortable>{
	
	private String name;
	private int age;
	
	public PersonSortable(String name,int age){
		super();
		this.name = name;
		this.age = age;
	}

	@Override
	public String toString() {
		return name +"-"+ age;
	}
	
	@Override
	public int compareTo(PersonSortable o) {
		if (this.name.compareTo(o.name)>0) 
			return 1;			
		else if(this.name.compareTo(o.name)<0)			
			return -1;		
		else{
			if (this.age>o.age) 			
				return 1;		
			else if(this.age<o.age)
				return -1;
			else
				return 0;
			}		
	}
}

public class Min {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		String name;
		int age;
		PersonSortable [] person = new PersonSortable[n];
		for (int i= 0; i<n ; i++) {
			name = in.next();
			age = in.nextInt();
			person[i] = new PersonSortable(name,age);
		}
		
		Arrays.sort(person);
		for (int j =0 ; j<person.length;j++) {
			System.out.println(person[j]);
		}
		
		System.out.println(Arrays.toString(PersonSortable.class.getInterfaces()));

	}

}
